package com.gitee.melin.bee.core.jdbc.dialect;

import static com.gitee.melin.bee.core.jdbc.enums.SaslMchanism.PLAIN;

import com.gitee.melin.bee.core.jdbc.enums.DataSourceType;
import com.gitee.melin.bee.core.jdbc.relational.ConnectionInfo;
import com.gitee.melin.bee.core.jdbc.relational.MetaDataSource;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;

public class KafkaSaslSslDialectTest1 {

    // @org.junit.Test
    public void test() throws Exception {
        Map<String, String> properties = Maps.newHashMap();
        // 使用HikariCP 数据源，参数请参考：https://github.com/brettwooldridge/HikariCP
        properties.put("maximumPoolSize", "2");

        ConnectionInfo connection = ConnectionInfo.builder()
                .withCode("xxx")
                .withDataSourceType(DataSourceType.KAFKA)
                .withEndpoint("172.18.1.52:9093")
                .withProtocol("SASL_SSL")
                .withSaslMchanism(PLAIN) // SCRAM-SHA-256、SCRAM-SHA-512
                .withUsername("admin")
                .withPassword("admin123456")
                .withSslKeyPassword("123456")
                .withSslTruststoreLocation("/Users/melin/Documents/codes/bee/src/test/resources/kafka/truststore.jks")
                .withSslTruststorePassword("123456")
                .withSslKeystoreLocation("/Users/melin/Documents/codes/bee/src/test/resources/kafka/keystore.jks")
                .withSslKeystorePassword("123456")
                .build();

        try (JdbcDialect dialect = JdbcDialectHolder.getJdbcDialect(connection)) {
            MetaDataSource dataSourceInfo = dialect.testConnection(connection);
            System.out.println(dataSourceInfo);

            List<String> topics = dialect.getTableNames("");
            System.out.println(topics);
        }
    }
}
